from django.db import models


class Cate(models.Model):
    name = models.CharField(max_length=20, verbose_name="分类表")
    pic = models.ImageField(upload_to="static/pic", null=True)

    class Meta:
        db_table = "cates"
        verbose_name = "分类表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Goods(models.Model):
    name = models.CharField(verbose_name="商品名", max_length=20)
    intro = models.CharField(verbose_name="简介", max_length=50)
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='价格')
    unit = models.CharField(verbose_name="单位", max_length=20)
    cate = models.ForeignKey(Cate, on_delete=models.CASCADE, verbose_name="分类")
    repertory = models.IntegerField(verbose_name="库存")
    pic = models.ImageField(verbose_name="图片", upload_to="static/pic")
    cat = models.IntegerField(verbose_name="浏览量", default=0)
    detail = models.TextField(verbose_name="详情")

    class Meta:
        db_table = "goods"
        verbose_name = "商品表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
